<body>

<div class="admin-biaogelist">
    <div class="listbiaoti am-cf">
        <ul class="am-icon-flag on"> 用户管理</ul>
        <dl class="am-icon-home" style="float: right;">当前位置： 首页 > <a href="#">用户管理</a></dl>
    </div>
    <div class="fbneirong">

        <p style="margin-left: 200px;">
            用户名
            <input type=""  name="username"  >
            手机号
            <input type=""  name="phone"  >
            <input type="button" value="查找"   class="search am-btn am-btn-secondary am-radius " >
            <input type="button" value="新增用户"  style="margin-right: "  class="adduser am-btn am-btn-secondary am-radius " >
        </p>


        <div  id="grouplist" style="display: none">
            <select name="grouplist" >
                <?Php   foreach ($grouplist as $id=>$v){?>
                    <option  value="<?php  echo$v['id'];  ?>"><?php  echo$v['name'];  ?></option>
                <?php } ?>
            </select>
        </div>


        <div  id="teamlist" style="display: none">
            <select name="teamlist" >
                <?Php   foreach ($teamlist as $id=>$v){?>
                    <option  value="<?php  echo$v['id'];  ?>"><?php  echo$v['name'];  ?></option>
                <?php } ?>
            </select>
        </div>


        <div  id="channellist" style="display: none">
            <select name="channellist" >
                <?Php   foreach ($channellist as $id=>$v){?>
                    <option  value="<?php  echo$v['id'];  ?>"><?php  echo$v['name'];  ?></option>
                <?php } ?>
            </select>
        </div>




        <br />
        <form class="am-form am-g">
            <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
                <thead>
                <tr class="am-success">
                    <th class="table-check"><input type="checkbox" /></th>
                    <th class="table-type">用户ID</th>
                    <th class="table-type">用户名</th>
                    <th class="table-type">类型</th>
                    <th class="table-type">用户密码</th>
                    <th class="table-type">手机号</th>
                    <th class="table-type"style="width: 100px;">账户余额</th>
                    <th class="table-type"style="width: 100px;">金币余额</th>
                    <th class="table-type"style="width: 100px;">渠道</th>
                    <th class="table-type"style="width: 100px;">团队</th>
                    <th class="table-type" style="width: 100px;">状态</th>
                    <th class="table-set" style="width:300px;">操作</th>
                </tr>

                <tbody class="impowdith">
                </tbody>
                </thead>
            </table>
            <div id="Pagination" style="margin:20px auto" style="display:none"></div>
        </form>
    </div>
</div>
</body>

</div>
</html>


<script>




    var grouplist=$("#grouplist").html();


    var on_request=false;
    var page=1;



    $(".search").click(function () {
        GetBusinessList();
    });


    adduser();
    /**
     * 新增用户
     */
    function  adduser() {
        $(".adduser").click(function () {
            layer.open({
                title: '修改用户',
                btn: '确认',
                area: ['500px', '300px'],
                content: ' <form action="" method="post" id="new-zf-psd">\n' +
                    '        <div>\n' +
                    '            <label for="">账户名：</label><input type="text"   name="username"  value="">\n' +
                    '        </div>\n' +
                    '        <div>\n' +
                    '            <label for="">密码：</label><input type="text"   name="password"  value="" >\n' +
                    '        </div>\n' +
                    '        <div>\n' +
                    '            <label for="">手机：</label><input type="text"   name="phone"  value="" >\n' +
                    '        </div>\n' +
                    '        <div>\n' +
                    '            <label for="">类型：</label>\n' +grouplist+
                    '        </div>\n' +
                    '    </form>',
                yes: function () {
                    var url = "<?php echo base_url(); ?>/Customer/adduser";

                    var username=$("#new-zf-psd input[name='username']").val();
                    var password=$("#new-zf-psd input[name='password']").val();
                    var phone=$("#new-zf-psd input[name='phone']").val();
                    var group=$("#new-zf-psd select[name='grouplist']").val();


                    var postdata = {
                        'username': username,
                        'password': password,
                        'phone': phone,
                        'group': group
                    };


                    $.post(url, postdata, function (data) {
                        on_request = false;
                        if(data.code==0){
                            layer.msg("添加成功",{
                                time: 2000, //2s后自动关闭
                                /*   btn: ['明白了', '知道了', '哦']*/
                            });
                            GetALLuserList();

                        }else{
                            layer.msg(data.msg);
                        }

                    }, 'json');

                }
            });




        });


    }

    function edite() {
        $(".edite").click(function () {
            var user_id=$(this).parents("tr").attr("user_id");
            var group_id=$(this).parents("tr").attr("group_id");
            var team=$(this).parents("tr").attr("team");
            var channel=$(this).parents("tr").attr("channel");



            var username=$(this).parents("tr").find("td:eq(2)").text();
            var password=$(this).parents("tr").find("td:eq(4)").text();
            var phone=$(this).parents("tr").find("td:eq(5)").text();


       /*     var channel=$(this).parents("tr").find("td:eq(8)").text();
            var team=$(this).parents("tr").find("td:eq(9)").text();*/

            $("select[name='grouplist']").find("option[value='"+group_id+"']").attr("selected",true);

            $("select[name='teamlist']").find("option[value='"+team+"']").attr("selected",true);
            $("select[name='channellist']").find("option[value='"+channel+"']").attr("selected",true);




            grouplist=$("#grouplist").html();
            var    teamlist=$("#teamlist").html();
            var   channellist=$("#channellist").html();







            layer.open({
                title: '新增用户',
                btn: '确认',
                area: ['500px', '300px'],
                content: ' <form action="" method="post" id="new-zf-psd">\n' +
                    '        <div>\n' +
                    '            <label for="">账户名：</label><input type="text"   name="username"  value="'+username+'">\n' +
                    '        </div>\n' +
                    '        <div>\n' +
                    '            <label for="">密码：</label><input type="text"   name="password"  value="'+password+'" >\n' +
                    '        </div>\n' +
                    '        <div>\n' +
                    '            <label for="">渠道：</label>' +channellist+
                    '        </div>\n' +
                    '        <div>\n' +
                    '            <label for="">团队：</label>' +teamlist+
                    '        </div>\n' +
                    '        <div>\n' +
                    '            <label for="">手机：</label><input type="text"   name="phone"  value="'+phone+'" >\n' +
                    '        </div>\n' +
                    '        <div>\n' +
                    '            <label for="">类型：</label>\n' +grouplist+
                    '        </div>\n' +
                    '    </form>',
                yes: function () {
                    var url = "<?php echo base_url(); ?>/Customer/edituser";
                    var username=$("#new-zf-psd input[name='username']").val();
                    var password=$("#new-zf-psd input[name='password']").val();
                    var channel=$("#new-zf-psd select[name='channellist']").val();
                    var team=$("#new-zf-psd select[name='teamlist']").val();
                    var phone=$("#new-zf-psd input[name='phone']").val();
                    var group=$("#new-zf-psd select[name='grouplist']").val();
                    var postdata = {
                        'user_id': user_id,
                        'channel': channel,
                        'team': team,
                        'username': username,
                        'password': password,
                        'phone': phone,
                        'group': group
                    };


                    $.post(url, postdata, function (data) {
                        on_request = false;
                        if(data.code==0){
                            layer.msg("修改成功",{
                                time: 2000, //2s后自动关闭
                                /*   btn: ['明白了', '知道了', '哦']*/
                            });
                            GetALLuserList();

                        }else{
                            layer.msg(data.msg);
                        }

                    }, 'json');

                }
            });


        });
        
    }

    function setlisthtnml(data) {
        var html = "";
        if (data.list.length > 0) {
            $.each(data.list, function (key, value) {
                html = html +
                    '<tr user_id="'+value.id+'"  group_id="'+value.group+'"   team="'+value.team+'"   channel="'+value.channel+'" ><td><input type="checkbox" /></td>\n' +
                    '<td>' + value.id + '</td>\n' +
                    '<td>' + value.username + '</td>\n' +
                    '<td>' + value.type + '</td>\n' +
                    '<td>' + value.password + '</td>\n' +
                    '<td>' + value.phone + '</td>\n' +
                    '<td>' + value.money + '</td>\n' +
                    '<td>' + value.gold + '</td>\n' +
                    '<td>' + value.channelname + '</td>\n' +
                    '<td>' + value.teamname + '</td>\n' +
                    '<td>' + value.status + '</td>\n' +
                    '<td >' +
                    '<span     class="am-btn am-btn-secondary am-radius edite" >修改账户</span>\n' +
                    '</tr>';
            });
            $(".impowdith").html(html);
            $('#Pagination').show();

            edite();

        } else {
            html += '<li><div style="width:100%;text-align:center;">&nbsp暂无数据</div></li>';
            $(".impowdith").html(html);
            $('#Pagination').hide();
        }
    }

    GetALLuserList();

    function GetALLuserList() {
        var url = "<?php echo base_url(); ?>/Customer/GetALLuserList";
        var phone=$("input[name='phone']").val();
        var date1=$("input[name='date1']").val();
        var date2=$("input[name='date2']").val();

        var postdata = {
            'page': page,
            'eapge': 15,
            'phone': phone

        };
        $.post(url, postdata, function (data) {
            on_request = false;
            setlisthtnml(data);
            setPagination("Pagination", data.count, page, data.epage, function (clickPage) {
                page = parseInt(clickPage) + 1;
                GetALLuserList();
            });
        }, 'json');

    }






</script>